package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
*
* Map常见方法
* */
public class MapFunction {
    public static void main(String[] args) {
        Map<String,Integer> map=new HashMap<>();
        //添加元素
        map.put("Java",98);
        map.put("Python",75);
        map.put("C",55);
        map.put("C++",65);
        map.put("C#",59);
        map.put("JavaScript",86);
        System.out.println(map);
        //删除
        map.remove("Java");
        System.out.println(map);
        //以键查值
        System.out.println("JavaScript="+map.get("JavaScript"));
        //是否包含键、值
        System.out.println("是否包含Python键："+map.containsKey("Python"));
        System.out.println("是否包含Go键："+map.containsValue("Go"));
        System.out.println("是否包含59值："+map.containsValue(59));
        System.out.println("是否包含1值："+map.containsValue(1));
        //清空元素
//        map.clear();
        //判空
//        System.out.println(map.isEmpty());
        System.out.println("长度为："+map.size());
        System.out.println("========================================");
        //获取所有键
        Set<String> keys = map.keySet();
        for(String key:keys){
            System.out.println(key);
        }
        System.out.println("========================================");
        //获取所有值--》可重复
        Collection<Integer> values = map.values();
        for(Integer value:values){
            System.out.println(value);
        }
        System.out.println("========================================");
    }
}
